{
  Nassy - anti-spam for IM clients
  Copyright (C) 2008-2009 Denis Shemanayev aka nis
                          mailto: nis@nis.org.ua
                          mailto: Denis.Shemanayev@gmail.com

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License along
  with this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
}
{ $Id: uDebug.pas 4 2009-06-14 11:10:14Z Denis.Shemanayev $ }

unit uDebug;

interface

procedure DLog(const Text: WideString);

implementation

uses
  SyncObjs, Windows, SysUtils;

var
  CS: TCriticalSection;
  Fl: THandle;
  buf: array[0..MAX_PATH] of WideChar;
  s: WideString;

procedure DLog(const Text: WideString);
var
  s: WideString;
  d: Cardinal;
begin
  CS.Enter;
  s := WideString(FormatDateTime('hh:nn:ss.z', Now)) + WideChar(#9) + Text + WideChar(#13)+WideChar(#10);
  try
    WriteFile(Fl, PWideChar(s)^, Length(s) * SizeOf(WideChar), d, nil);
  finally
    FlushFileBuffers(Fl);
    CS.Leave;
  end;
end;

initialization
  CS := TCriticalSection.Create;
  GetModuleFileNameW(HInstance, buf, SizeOf(buf));
  s := WideString(buf) + WideString(FormatDateTime('_hh.nn.ss', Now)) + WideString('.log');
  Fl := CreateFileW(PWideChar(s), GENERIC_READ or GENERIC_WRITE, 0, nil, OPEN_ALWAYS, 0, 0);

finalization
  CloseHandle(Fl);
  CS.Free;

end.
